import {ComponentType} from 'vc';
import {useRequest} from 'vue-request';
import {getMonitorItem, getMonitorStation} from "@/views/modules/enterprise/apis";
import {formatSubData} from "@/views/modules/enterprise/modules/pollution-monitoring/formatData";

export function useScreen(companyId, type) {
  const PAGE_SIZE = 10;

  const queryData = reactive<any>({
    pageNum: 1,
    pageSize: PAGE_SIZE,
    sortRule: '',
    searchTxt: ''
  });


  // 监测项目
  const {data: monitorItemData} = useRequest(getMonitorItem, {
    defaultParams: [{id: companyId, type: type}]
  });

  // 监测点
  const {data: monitorStationData} = useRequest(getMonitorStation, {
    defaultParams: [{id: companyId, type: type}]
  });


  const screen = computed(() => {
    return [
      {
        title: '监测项目',
        component: ComponentType.MULTIPLETILED,
        options: monitorItemData.value || [],
        submitFn: (data) => {
          queryData.monitorItem = formatSubData(data);
        }
      },
      {
        title: '监测点',
        component: ComponentType.MULTIPLETILED,
        options: monitorStationData.value || [],
        submitFn: (data) => {
          queryData.monitorStation = formatSubData(data);
        }
      },
      {
        title: '采样时间',
        component: ComponentType.DATE,
        type: 'daterange',
        shortcuts: [30, 90, 180, 365, 365 * 3],
        submitFn: (data) => {
          queryData.monitorStartDate = data[0];
          queryData.monitorEndDate = data[1];
        }
      }
    ];
  });

  return {
    PAGE_SIZE,
    screen,
    queryData
  };
}
